

function addformimage()
{
   $("#addform").append('<div id="feature'+rowdiv+'" class="itPlg addImgPlg featureclass">'+dataform['image']+"</div>");
   var rownow=rowdiv;
   //var $form = $('#feature'+rownow+' .royalSlider');
   //$('#feature'+rownow+' .group').colorbox({
//preloading: true,
//modal: true,
//transition: 'none',
//speed: 0, 
//transition:"fade"

//});
  
  

 // var rowg=1;

  var rowgnow=1;
  
  
   $('#feature'+rownow+' .uploadbutton').iuploader({
         'link':serviceinfo+'iupload',
         'accept':'image/*',
         'group':rowgnow,

         'type':['jpg', 'jpeg', 'png', 'gif'],
         'onUploadFinish':function(filename,filelink,setting){
         
         
         
         
         getpopupboxresize(640,360,filelink,setting['originalwidth'],setting['originalheight'],
         
         function(filename2,filelink2,width2,height2,imgmid2){
         var rowgnow2=setting['group'];        
         $('#feature'+rownow+' .image'+rowgnow2+' .plgArea').html('<a target="_blank" href="'+filelink+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="360" width="640" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="filelink[]"]').val(filelink);
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="filelinkcrop[]"]').val(filelink2);                 
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="fileold[]"]').val(setting.fileold);      
         $("#width-"+setting.id).val(setting.originalwidth);
         $("#height-"+setting.id).val(setting.originalheight);      
         $("#imgmid-"+setting.id).val(setting.imgmid);       
         $("#simgmid-"+setting.id).val(imgmid2);               
         $("#widthcrop-"+setting.id).val(width2);
         $("#heightcrop-"+setting.id).val(height2);    
         
          closepopup();  
         }
         ,setting['imgmid']
         
         );
         //alert(filename);
         }
   });
  
   $('#feature'+rownow+' .cloudbutton').click(function() {
          //console.log("testdata");
          //var rowgnow3=rowgnow;
          var rowgnow3=1;
        //alert("Handler for .click() called.");
          getpopupcloud(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 

        $('#feature'+rownow+' .image'+rowgnow3+' .plgArea').html('<a target="_blank" href="'+$('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val()+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="360" width="640" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);

        closepopup();  

          
          },
          
          
          function(filename,filelink,width,height,imgmid,indexnow){
            
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,
          rowgnow
          ,640
          ,360
          
          );

   });
   
   $('#feature'+rownow+' .deletebutton').click(function() {
   
   var rowgnow3=1;
   

   $('#feature'+rownow+' .image'+rowgnow3+' .plgArea a').remove();
   
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val('');
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val('');           
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val('');
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val('');
   
   
   
    $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val('');
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val('');                                    
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val('');         
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val('');
   
   });
   
   $('#feature'+rownow+' .linkbutton').click(function() {
   var rowgnow3=1;
   //console.log("test");
   
   getpopuplink(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 
          
          
         $('#feature'+rownow+' .image'+rowgnow3+' .plgArea').html('<a target="_blank" href="'+$('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val()+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="360" width="640" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);
        // $.colorbox.close("User added succesfully"); 
        closepopup();  
          
          },
          function(filename,filelink,width,height,imgmid,indexnow){
            

            $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,
          rowgnow
          ,640
          ,360
   );
   
   });
   
   $('#feature'+rownow+' .deleterowbutton').click(function(){
   
    $('#feature'+rownow).remove();
    
   });
  
  
 
  
 
  
  
  
  
  
  
  
  
  
  
  
  //$('#feature'+rownow+' .group')
   
   
  
   

  
  
   rowdiv++;
}
function saveformimage(id,plugid)
{
        var obj={};
        var imgmid1=$("#"+id+' .image1 input[name="imgmid[]"]').val();
        var simgmid1=$("#"+id+' .image1 input[name="simgmid[]"]').val();
        detail=$("#"+id+' input[name="detail[]"]').val();
        obj={plugid:plugid,imgmid:imgmid1,simgmid:simgmid1,detail:detail};
       
        return obj;
}
function getformimage(dataplugin)
{
var code = '<div class="ldIt wrpImgLd clBg4 w640" onclick="openmaingallery('+dataplugin.simgmid+')">\n';
code += '<div class="icoDefLd">\n';
code += '<span class="ico icoImgDefLd"></span>\n';
code += '<span>Image</span>\n';
code += '</div>\n';
code += '<div class="wrpImgDesLd">\n';
code += '<a href="javascript:void(0)"   class="galleryimage" ><img  title="'+dataplugin.img.newpath+'" width="640" height="360" alt="'+dataplugin.img.width+'|'+dataplugin.img.height+'" id="img-'+dataplugin.simgmid+'" src="'+dataplugin.simg.newpath+'"></a>\n';

var displayset="";
if(dataplugin.detail=="")
{
displayset='style="display:none"';
}

code += '<div class="desImgLd clTxtW" '+displayset+' >\n';
code += '<div class="ovlLd ovlImgLd w640" >\n';
code += '<p class="cutTxt">'+dataplugin.detail+'</p>\n';
code += '</div>\n';
code += '</div>\n';

code += '</div>\n';
code += '</div>';
return code;


}
function editformimage(datarow)
{
       addformimage();

       var rownow= rowdiv-1;
       var rowgnow2=1;
       
       
    $('#feature'+rownow+' .image'+rowgnow2+' .plgArea').html('<a target="_blank" href="'+datarow.img.newpath+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="360" width="640" src="'+datarow.simg.newpath+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
    $('#feature'+rownow+' .image'+rowgnow2+' input[name="imgmid[]"]').val(datarow.imgmid);
    $('#feature'+rownow+' .image'+rowgnow2+' input[name="simgmid[]"]').val(datarow.simgmid);
    $('#feature'+rownow+' input[name="detail[]"]').val(datarow.detail);   


}